/*****************************************************************
Copyright (c)  2017 Qualcomm Technologies International, Ltd.

PROJECT
    source
    
FILE NAME
    source_aghfp_data.c

DESCRIPTION
    It contains AGHFP configuration data and Global data which need to be used by other modules
    
*/

#include <hfp.h>
#include <csrtypes.h>
#include <boot.h>
#include <byte_utils.h>
#include <print.h>
#include <string.h>
#include <stdlib.h>

#include "source_aghfp_data.h"
#include "source_aghfp.h"
#include "source_private.h"

#define AGHFP_MAX_CONN_RETRIES 2
/*
static sync_packet_config_def_t aghfp_sync_packet =
{
    .SCOhv1enable = 1,
    .SCOhv2enable = 1,
    .SCOhv3enable = 1,
    .ESCOev3enable = 1,
    .ESCOev4enable = 0,
    .ESCOev5enable = 0,
    .edr2ev3disable = 0,
    .edr3ev3disable = 1,
    .edr2ev5disable = 1,
    .edr3ev5disable = 1
};
*/

static source_aghfp_writable_data_config_def_t aghfp_profile_value =
{
    .AGHFPConnectionFailed_s = 0x7D0,
    .hfpProfile              = HFP_PROFILE_1_7
};

uint16 sync_pkt_types = 0;

/*************************************************************************
NAME
    aghfp_source_data_init

DESCRIPTION
    Function to Initialise the AGHfp configuration data.

RETURNS
    void

**************************************************************************/
void aghfp_source_data_init(void)
{
    aghfp_source_init_globaldata(NULL);
}
/*************************************************************************
NAME
    sourceAGHfpDataCreateSyncPktTypes

DESCRIPTION
     Creates the variable named sync_pkt_types from sco_packet,esco_packet and 
     edr_packet structure variables.

RETURNS
    void

.SCOhv1enable = 1,
.SCOhv2enable = 1,
.SCOhv3enable = 1,
.ESCOev3enable = 1,
.ESCOev4enable = 0,
.ESCOev5enable = 0,
.edr2ev3disable = 1,
.edr3ev3disable = 1,
.edr2ev5disable = 1,
.edr3ev5disable = 1,



***************************************************************************/
void aghfp_source_data_create_syncpkt_types(void)
{
    /*
    sync_pkt_types |= (aghfp_sync_packet.SCOhv1enable)&0xFFFF;
    sync_pkt_types |= ((aghfp_sync_packet.SCOhv2enable)<<1)&0xFFFF;
    sync_pkt_types |= ((aghfp_sync_packet.SCOhv3enable)<<2)&0xFFFF;
    sync_pkt_types |= ((aghfp_sync_packet.ESCOev3enable)<<3)&0xFFFF;
    sync_pkt_types |= ((aghfp_sync_packet.ESCOev4enable)<<4)&0xFFFF;
    sync_pkt_types |= ((aghfp_sync_packet.ESCOev5enable)<<5)&0xFFFF;
    sync_pkt_types |= ((aghfp_sync_packet.edr2ev3disable)<<6)&0xFFFF;
    sync_pkt_types |= ((aghfp_sync_packet.edr3ev3disable)<<7)&0xFFFF;
    sync_pkt_types |= ((aghfp_sync_packet.edr2ev5disable)<<8)&0xFFFF;
    sync_pkt_types |= ((aghfp_sync_packet.edr3ev5disable)<<9)&0xFFFF;
    */
    sync_pkt_types = sync_all_sco|sync_ev3|sync_3ev3|sync_2ev5|sync_3ev5;
}
/*************************************************************************
NAME
    aghfp_source_data_get_syncpkt_types

DESCRIPTION
    Returns the value of sync_pkt_types variable.

RETURNS
    The value of the variable 'sync_pkt_types' which is derived from the values of the 
    member variables of the structure sync_packet.The value of these member structure
    variables is initialized in the module xml file of AGHFP.

***************************************************************************/
uint16 aghfp_source_data_get_syncpkt_types(void)
{
    return sync_pkt_types;
}
/*************************************************************************
NAME
    aghfp_get_max_connection_retries

DESCRIPTION
    Helper function to get the maximum number of connection retries whenever aghfp 
    connection fails..

RETURNS
    The maximum connection retries as read from the config block.

**************************************************************************/
uint16 aghfp_get_max_connection_retries(void)
{
    return AGHFP_MAX_CONN_RETRIES;
}
/*************************************************************************
NAME
    aghfp_get_profile_Value

DESCRIPTION
    Helper function to get the supported HFP profile .

RETURNS
    The current profile which is configured in the config block. The possible values:
    0 = HFP_PROFILE_DISABLED,
    1 = HFP_PROFILE_1_6,
    2 = HFP_PROFILE_1_7
    
**************************************************************************/
AGHFP_PROFILE_T aghfp_get_profile_Value(void)
{       
    return aghfp_profile_value.hfpProfile;
}
/*************************************************************************
NAME
    source_timers_get_aghfp_connection_failed_timer

DESCRIPTION
    Helper function to Get the AGHFP Connection Failed timer.

RETURNS
    The value as configured in the module xml file of  AGHFP.

**************************************************************************/
uint16 aghfp_get_connection_failed_timer(void)
{
    return aghfp_profile_value.AGHFPConnectionFailed_s;
}
/*************************************************************************
NAME
    source_timers_set_aghfp_connection_failed_timer

DESCRIPTION
    Helper function to set the AGHFP Connection Failed timer value.

RETURNS
    TRUE is value was set ok, FALSE otherwise.
*/
bool aghfp_set_connection_failed_timer(uint16 timeout)
{
    aghfp_profile_value.AGHFPConnectionFailed_s = timeout ;
    return TRUE;
}

